import request from "@/axios";

const prefix = "/user";

const login = function({ userName, password }) {
  return request({
    url: prefix + "/login",
    method: "post",
    data: { userName, password }
  });
};

const info = function(token) {
  return request({
    url: prefix + "/info/" + token,
    method: "post"
  });
};

const register = function({ userName, password, email, verCode }) {
  return request({
    url: prefix + "/register/" + verCode,
    method: "post",
    data: { userName, password, email }
  });
};

const getVerCode = function(email) {
  return request({
    url: prefix + "/sendVerificationCode/" + email
  });
};

const checkUsername = function(username) {
  return request({
    url: prefix + "/isExistUsername/" + username
  });
};

const checkEmail = function(email) {
  return request({
    url: prefix + "/isExistEmail/" + email
  });
};

const resetPasswd = function(params) {
  return request({
    url: prefix + "/resetPassword",
    params: params
  });
};

const getRestPasswdVerificationCode = function(email) {
  return request({
    url: prefix + "/sendResetPasswdVerificationCode/" + email
  });
};

export {
  login,
  info,
  register,
  getVerCode,
  checkUsername,
  checkEmail,
  resetPasswd,
  getRestPasswdVerificationCode
};
